﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class MachineUtilizationPercentage : Objective
    {
        public MachineUtilizationPercentage()
            : base()
        {
        }
        public MachineUtilizationPercentage(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        protected override void Logic()
        {

            AllocationList allocations = new AllocationList(Solution.GetAllocationRows());
            MachineList machines = new MachineList(SchEduData.Machine);

            int makeSpan = allocations.GetMakespan();
            int hundredPercentage = makeSpan + 1;


            foreach (SchEduDataSet.MachineRow machine in machines)
            {
                int utilization = allocations.GetMachineUtilization(machine);

                double utilizationPergentage = Math.Round((double)utilization / hundredPercentage * 100, 2);

                GeneratePerformanceRow();

                performance.MachineGuid = machine.Guid;
                performance.Title = string.Format("{0}-{1}", performance.Title, machine.Name);
                performance.Value = utilizationPergentage;

            }


        }

        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Machine Utilization (%)";
                aboutInfo.Guid = new Guid("{89153EE7-2405-4eb4-848D-3C45CB5749C2}");
                aboutInfo.Description = Resources.MachineUtilizationPercentageDescription;
                return aboutInfo;
            }
        }

    }
}
